package topcoder.srm500;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class SRMCards {

	public int maxTurns2(int[] cards) {
		Set<Integer> cardSet = new HashSet<Integer>();
		
		for(int c: cards)
			cardSet.add(c);
		
		Arrays.sort(cards);
		
		int ans = 0;
		
		for(int c : cards) {
			if(cardSet.contains(c)) {
				ans++;
				cardSet.remove(c);
				if(cardSet.contains(c+1)) {
					cardSet.remove(c+1);
				}
			}
		}
		
		return ans;

	}
	
	public int maxTurns(int[] cards)
	{
		int ans = 0;
		Arrays.sort(cards);
		for(int i = 0; i < cards.length -1; i++) {
			if(cards[i] == 0)
				continue;
			ans++;
			if(cards[i+1] - cards[i] == 1)
				cards[i+1] = 0;
			cards[i] = 0;
				
		}
		if(cards[cards.length -1] !=0)
			ans++;
		return ans;
	}

	public static void main(String[] args) {
		SRMCards srm = new SRMCards();
		
		int[] cards = 	
			{100, 200, 300, 301, 302}


		;
		
		System.out.println(srm.maxTurns(cards));


	}

}
